<template>
  <transition
    enter-to-class="animate__animated animate__fadeInRight"
    enter-active-class="animate__animated animate__fadeInRight"
    leave-to-class="animate__animated animate__fadeOutDown"
    leave-active-class="animate__animated animate__fadeOutDown"
  >
    <div class="web-img">
      <app-return :option="obj"></app-return>
      <div class="form">
        <input v-model="message" type="text" placeholder="附加信息..." />
      </div>
      <div class="add-box">
        <input @change="myChange" type="file" />
        <span>+</span>
      </div>
      <div class="img-box">
        <img :src="`${imgUrl}`" alt="" />
      </div>
    </div>
  </transition>
</template>

<script>
import AppReturn from "@/components/app-return.vue";
export default {
  name: "Img",
  components: {
    AppReturn,
  },
  data() {
    return {
      message:"",
      imgUrl: "",
      obj:{}
    };
  },
  methods: {
    myChange(event) {
      let imgInfo = event.target.files[0];
      let fileReader = new FileReader();

      fileReader.onload = (data) => {
        let urlStr = data.target.result;
        this.imgUrl = urlStr;
        this.obj.message = this.message;
        this.obj.imgUrl = this.imgUrl;
        this.obj.id = Math.random();
      };

      fileReader.readAsDataURL(imgInfo);
    }
  },
};
</script>

<style lang="less" scoped>
.web-img {
  padding-top: 50px;
  box-sizing: border-box;
  padding: 50px 15px 0;
  .form {
    width: 100%;
    height: 40px;
    margin-bottom: 40px;
    input {
      width: 100%;
      box-sizing: border-box;
      height: 100%;
      font-size: 16px;
    }
  }
  .add-box {
    width: 80px;
    height: 80px;
    border: 1px solid #ccc;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 20px;
    position: relative;
    input[type="file"] {
      position: absolute;
      width: 100%;
      height: 100%;
      opacity: 0;
      z-index: 1000;
    }
    span {
      position: absolute;
      left: 28px;
      top: 17px;
      z-index: 0;
    }
  }
  .img-box {
    width: 320px;
    // height: 120px;
    padding: 30px 0;
    overflow: hidden;
    border: 1px solid #ccc;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
</style>